package com.cherrish.demo;

import java.util.Random;

/**
 * @author ccl
 * @time 2019-01-24 16:19
 * @name TestAlgorithml
 * @desc:
 */
public class TestAlgorithml {
    public static void main(String[] args) {

        int arr[] = new int[]{66,55,77,33,44,99,88,11,999,77,22,111,333,222,111,444,666,55,555,888,66,777,666,11,22,33};
        long start = System.nanoTime();
        insertSort(arr, arr.length);
        long end = System.nanoTime();
        System.out.println(end - start);
        print(arr);

    }

    static private void insertSort(int[] arr, int len){
        for(int i = 1; i < len; i++){
            int temp = arr[i];
            int j = i - 1;
            while (j >= 0 && arr[j] > temp){
                arr[j + 1] = arr[j];
                j--;
            }
            arr[j + 1] = temp;
        }
    }

    static private void swap(int[] arr, int x, int y){
        arr[x] = arr[x] ^ arr[y];
        arr[y] = arr[x] ^ arr[y];
        arr[x] = arr[x] ^ arr[y];
    }

    static private void print(int[] arr){
        System.out.println();
        for(int i = 0; i < arr.length; i++){
            System.out.print(arr[i] + "  ");
        }
        System.out.println();
    }
}
